

package com.cisdi.info.mh.controller.User;

import com.cisdi.info.mh.dto.User.UserEditDto;
import com.cisdi.info.mh.entity.User.User;
import com.cisdi.info.mh.service.User.UserService;
import com.cisdi.info.simple.dto.base.PageDTO;
import com.cisdi.info.simple.dto.base.PageResultDTO;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;



/**module
{
"mh/User/User": {
"code": "mh/User/User",
"name1": "用户",
"url": "/mh/User/User",
"route": "/mh/User/User",
"iconClass": "",
"displayIndex": 1,
"parentCode": "mh/User",
"parentName": "用户管理",
"moduleType": "电脑模块",
"isInUse": "是",
"routeParamsObj": "",
"permissions":
	[
	{
	"code": "mh_User_User_Add",
	"name1": "新增",
	"fullName": "mh.用户管理.用户.新增",
	"moduleCode": "mh/User/User",
	urls:[
		"/mh/User/User/createUser",
		"/mh/User/User/saveUser"
	]
	},
	{
	"code": "mh_User_User_Edit",
	"name1": "编辑",
	"fullName": "mh.用户管理.用户.编辑",
	"moduleCode": "mh/User/User",
	urls:[
		"/mh/User/User/findUserForEdit",
		"/mh/User/User/updateUser"
	]
	},
	{
	"code": "mh_User_User_Delete",
	"name1": "删除",
	"fullName": "mh.用户管理.用户.删除",
	"moduleCode": "mh/User/User",
	urls:[
	"/mh/User/User/deleteUser"
	]
	},
	{
	"code": "mh_User_User_View",
	"name1": "查看",
	"fullName": "mh.用户管理.用户.查看",
	"moduleCode": "mh/User/User",
	urls:[
	"/mh/User/User/findUsers",
	"/mh/User/User/findUserForView"
	]
	}
	]
}
}
*/

@RestController
@RequestMapping("/mh/User/User")
@CrossOrigin(allowCredentials = "true")
public class UserController {
	private static Logger logger = LogManager.getLogger();



	@Autowired private UserService userService;

	@PostMapping("/findUsers")
	public PageResultDTO findUsers(@RequestBody PageDTO pageDTO){
		return this.userService.findUsers(pageDTO);
	}

	@GetMapping("/findUser")
	public User findUser(@RequestParam Long userId)
	{
		return this.userService.findUser(userId);
	}

	@GetMapping("/findUserForView")
	public User findUserForView(@RequestParam Long userId)
	{
		return this.userService.findUserWithForeignName(userId);
	}

	@GetMapping("/findUserForEdit")
	public UserEditDto findUserForEdit(@RequestParam Long userId)
	{
		UserEditDto userEditDto = new UserEditDto();
		userEditDto.setUser(this.userService.findUserWithForeignName(userId));

		this.prepareUserEditDto(userEditDto);

		return userEditDto;
	}

	//创建新的用户
	@GetMapping("/createUser")
	public UserEditDto createUser()
	{
		UserEditDto userEditDto = new UserEditDto();
		userEditDto.setUser(new User());

		this.prepareUserEditDto(userEditDto);
		return userEditDto;
	}

	private void prepareUserEditDto(UserEditDto userEditDto)
	{
	}

	@PostMapping("/saveUser")
	public User saveUser(@RequestBody User user)
	{
		return this.userService.saveUser(user);
	}

	@PostMapping("/updateUser")
	public User updateUser(@RequestBody User user)
	{
		return this.userService.updateUser(user);
	}

	@GetMapping("/deleteUser")
	public void deleteUser(@RequestParam Long userId)
	{
		this.userService.deleteUser(userId);
	}
	@GetMapping("/findUsersWithIdNameById")
	public User findUsersWithIdNameById(@RequestParam Long userId)
	{
		return this.userService.findUsersWithIdNameById(userId);
	}

	@GetMapping("/findUsersWithIdNameByName")
	public List<User> findUsersWithIdNameByName(String userName)
	{
		return this.userService.findUsersWithIdNameByName(userName);
	}
	@GetMapping("/insertSelective")
	public void insertSelective(){
		System.out.println("1111");

	}
}

